# -*- ecoding: utf-8 -*-
# @ModuleName: baseapi
# @Author: wangwei 
# @Time: 2023/10/18 10:30
import requests

from common.logger import GetLogger


class RequestClient:
    session = requests.session()

    def __init__(self):
        self.url = None
        self.method = "post"
        self.params = None
        self.data = None
        self.json = None
        self.files = None
        self.headers = None
        self.dict_data = {}
        self.resp = None
        self.logger=GetLogger.get_logger()
        # self.logger = GetLogger.logger

    def send(self):
        if "url" not in self.dict_data:
            self.dict_data["url"] = self.url
        if "method" not in self.dict_data:
            self.dict_data["method"] = self.method
        if "params" not in self.dict_data:
            self.dict_data["params"] = self.params
        if "data" not in self.dict_data:
            self.dict_data["data"] = self.data
        if "json" not in self.dict_data:
            self.dict_data["json"] = self.json
        if "files" not in self.dict_data:
            self.dict_data["files"] = self.files
        if "headers" not in self.dict_data:
            self.dict_data["headers"] = self.headers
        if "params" not in self.dict_data:
            self.dict_data["params"] = self.params
        self.resp = RequestClient.session.request(**self.dict_data)
        self.logger.info(
            "******************************************************************************************************************")
        self.logger.info(f"请求数据：{self.dict_data}")
        self.logger.info(f"响应码：{self.resp.status_code}")
        self.logger.info(f"响应数据：{self.resp.text}")
        return self.resp
